package com.zc.study.thread.多线程第四章节.thread4_1_6;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Service {
    private Lock lock = new ReentrantLock();
    private Condition a = lock.newCondition();
    private Condition b = lock.newCondition();

    public void aWait() {
        try {
            lock.lock();
            System.out.println("a await");
            a.await();
            System.out.println("a 被唤醒");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            lock.unlock();
        }
    }
    public void bWait() {
        try {
            lock.lock();
            System.out.println("b await");
            b.await();
            System.out.println("b 被唤醒");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            lock.unlock();
        }
    }
    public void aSingal(){
        lock.lock();
        a.signal();
        lock.unlock();
    }
}
